package com.google.eclipse.mechanic.internal;

import static org.junit.Assert.*;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.variables.VariablesPlugin;
import org.junit.Test;

public class VariableManagerStringParserTest {

  private static final String MY_DUMMY_VARIABLE = "${my.dummy.variable}";

  @Test(expected = CoreException.class)
  public void testThatTestVariableDoesNotExists() throws CoreException {
    VariablesPlugin.getDefault().getStringVariableManager()
        .performStringSubstitution(MY_DUMMY_VARIABLE, true);
  }

  @Test
  public void testThatApplyReturnsTheInputValueIfSubstitutionFails() {
    assertEquals(MY_DUMMY_VARIABLE,
        VariableManagerStringParser.INSTANCE.apply(MY_DUMMY_VARIABLE));
  }

  @Test
  public void testThatApplyReturnsTheInputWithSubstitutedVariables() {
    String test = "My home directory is ${user_homedir}.";
    String expected = test.replace("${user_homedir}",
        System.getProperty("user.home"));

    assertEquals(expected, VariableManagerStringParser.INSTANCE.apply(test));
  }
}
